package tianhao.luo.huffmantree;

import lombok.Data;

/**
 * @author: tianhao.luo@hand-china.com 2021/6/25  下午4:02
 */
// 实现排序
@Data
public class Node implements Comparable<Node> {
    /**
     * 结点权值
     */
    int value;

    /**
     * 指向左子节点
     */
    Node left;

    /**
     * 指向右子节点
     */
    Node right;

    public Node(int value) {
        this.value = value;
    }

    @Override
    public int compareTo(Node o) {
        // 从小到大排序
        return this.value - o.value;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Node{");
        sb.append("value=").append(value);
        sb.append('}');
        return sb.toString();
    }

    public void preOrder() {
        System.out.println(this);

        if (this.left != null) {
            this.left.preOrder();
        }

        if (this.right != null) {
            this.right.preOrder();
        }

    }
}
